package com.hq.talk.http;

import android.util.Log;

import com.hq.talk.app.App;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 使用Retrofit2 Call异步请求时的回调
 */
public abstract class BaseCallback<T> implements Callback<T> {

    private static final String TAG = "BaseCallback";

    @Override
    public void onResponse(Call<T> call, Response<T> response) {
        Log.d(TAG, "code:" + response.code());
        if (response != null) {
            Object object = response.body();
            if (object != null && object instanceof ResponseData) {
                ResponseData responseData = (ResponseData) object;
                HandleRetCode.handlerExpire(App.getContext(), responseData);
            }
        }
        CallManager.remove(call);
    }

    @Override
    public void onFailure(Call<T> call, Throwable t) {
        Log.d(TAG, "error:" + t.getLocalizedMessage());
        CallManager.remove(call);
    }
}
